import 'package:blog/locator.dart';
import 'package:blog/tools/refresh_load_state.dart';
import 'package:flutter/material.dart';

import '../../api/api.dart';
import '../../src/generated/models/article.pb.dart';
import 'article_item.dart';

class ArticlesContainer extends StatefulWidget {
  List<ArticleItem> articles;
  Map<String, String> filter = {};

  ArticlesContainer(
      {Key? key, this.articles = const [], this.filter = const {}})
      : super(key: key);

  @override
  RefreshLoadState createState() =>
      RefreshLoadState<ArticlesContainer, ArticleItem>(
          initData: articles,
          getPage: (page, pageSize) async {
            var pageList = await locator<Api>()
                .getArticleItem(filter: filter, pageSize: pageSize, page: page);
            print("page:$page,pageSize:$pageSize, listNum:${pageList.length}");
            pageList.forEach((element) {
              print("id:${element.articleId} -- title:${element.title}");
            });
            return pageList;
          } ,
          itemBuilder: (val) => ArticleItemCard(blog: val));
}
